/*
-------------------------------------------------

	Autumn.h

	Dmitriy Kuzmenko (Dgut)

-------------------------------------------------
*/

#ifndef __AUTUMN_AUTUMN_H__
#define __AUTUMN_AUTUMN_H__

#include "Font.h"
#include "Game.h"
#include "Keys.h"
#include "Mathematics.h"
#include "Singleton.h"
#include "UI.h"
#include "pugixml.hpp"
#include <stdio.h>

namespace Autumn
{

#define gAutumn Autumn::Autumn::GetInstance()

class Sound;
class Stream;
class Texture;

class Autumn : public Singleton< Autumn >
{
								Autumn( void );
								~Autumn( void );
public:
	// Audio
	Sound * const				GetSound( const char * name ) const;
	const bool					PlaySound( const Sound * sound ) const;

	void						PlayStream( const char * name ) const;

	void						SoundEnable( bool enable ) const;
	const bool					IsSoundEnable( void ) const;

	void						MusicEnable( bool enable ) const;
	const bool					IsMusicEnable( void ) const;

	// Common
	const int					Delta( void ) const;
	const int					Time( void ) const;
	
	const int					Width( void ) const;
	const int					Height( void ) const;

	void						Save( void ) const;
	const bool					Load( void ) const;

	// Console
	void						Log( const char * text, ... );
	const char * const			GetLog( int line ) const;

	void						SetVariable( const char * name, const char * value );
	const char * const			GetVariable( const char * name ) const;
	const float					GetVariableFloat( const char * name ) const;

	void						AddCommand( const char * name, void ( * command )( int, const char * * ) );

	void						Execute( const char * text );

	// File
	FILE * const				OpenFile( const char * name, const char * mode ) const;

	// Game
	void						Frame( void ) const;
	void						Draw( void ) const;

	// Input
	const float * const			GetTouches( void ) const;
	const int					GetNumTouches( void ) const;

	const bool					GetKey( int key ) const;
	
	const bool					IsDown( float x, float y, float width, float height ) const;
	const bool					IsMove( float x, float y, float width, float height ) const;
	const bool					IsEnter( float x, float y, float width, float height ) const;
	const bool					IsUp( float x, float y, float width, float height ) const;

	const bool					IsDown( void ) const;
	const bool					IsUp( void ) const;
	const bool					IsMove( void ) const;

	const bool					IsKeyDown( int key ) const;
	const bool					IsKeyUp( int key ) const;

	// Render
	Texture * const				GetTexture( const char * name ) const;
	Font * const				GetFont( const char * name ) const;

	void						SetTexture( const Texture * texture ) const;
	void						SetFont( const Font * font ) const;

	void						SetOrthogonalProjection( float width, float height ) const;
	void						SetPerspectiveProjection( float fov ) const;
	void						PushMatrix( void ) const;
	void						PopMatrix( void ) const;
	void						Identity( void ) const;
	void						Rotate( float angle ) const;
	void						Rotate( float angle, float x, float y, float z ) const;
	void						Scale( float scale ) const;
	void						Scale( float x, float y, float z ) const;
	void						Translate( float x, float y, float z ) const;

	void						SetColor( float red, float green, float blue, float alpha = 1.f ) const;

	void						DrawRectangle( float x, float y, float width, float height ) const;
	void						DrawPolygon( float * verts, float * tverts, int numPoints ) const;

	void						Print( Font::HorizontalAlign ha, Font::VerticalAlign va, float x, float y, float scale, const char * text, ... ) const;

	// UI
	Screen * const				GetScreen( void ) const;
	void						SetScreen( Screen * screen ) const;

	// XML
	pugi::xml_document * const	LoadXML( const char * name ) const;
	const bool					SaveXML( pugi::xml_document * doc, const char * name ) const;

	friend class				Singleton< Autumn >;
};

extern Game * const				CreateGame( void );

extern const char * const		WNDCLASS_NAME;
extern const int				WND_STYLE;
extern const int				WND_WIDTH;
extern const int				WND_HEIGHT;

extern const int				VERSION;

}	// namespace Autumn

#endif	// !!! __AUTUMN_AUTUMN_H__ !!!